home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Draw Editor / Source / FrameProxy.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-11  |  8.3 KB  |  275 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        FrameProxy.h
  3.  
  4.     Contains:    CEmbeddedFrameProxy class definition
  5.  
  6.     Written by:    Dave Stafford
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.     
  10.     This file contains the definition for the class used to act as a place holder
  11.     for an ODFrame. A mock frame will contain a frame ID if it is NOT in memory. 
  12.     Otherwise, it will have a pointer to an ODFrame if it IS in memory.
  13. */
  14.  
  15. #ifndef _FRAMEPROXY_
  16. #define _FRAMEPROXY_
  17.  
  18. // -- DrawEditor --
  19.  
  20. #ifndef _COMPILERDEFS_
  21. #include "CompDefs.h"
  22. #endif
  23.  
  24. #ifndef _DRAWEDITORDEF_
  25. #include "DrawEditorDef.h"
  26. #endif
  27.  
  28. #ifndef _DRAWEDITORUTILS_
  29. #include "DrawEditorUtils.h"
  30. #endif
  31.  
  32. // -- OpenDoc --
  33.  
  34. #ifndef SOM_Module_OpenDoc_Global_Types_defined // For kODPresDefault
  35. #include "ODTypesM.xh"
  36. #endif
  37.  
  38. //=============================================================================
  39. // Forward Declarations
  40. //=============================================================================
  41. class DrawEditor;
  42. class CEmbeddingShape;
  43.  
  44. //=============================================================================
  45. // CFrameProxy
  46. //
  47. // Notions about the CFrameProxy class
  48. // 
  49. // Frames (embedded & display ) are lazily internalized through these objects. 
  50. // Frame proxies store a frame ID and/or a ODFrame pointer. A frame proxy can be 
  51. // constructed in 3 useful ways:
  52. //
  53. // 1. with a frame ID and a containing frame. This allows the frame to be 
  54. // loaded at a later time. 
  55. // 2. A frame proxy can be created with just a part reference and a containing
  56. // frame. In this case the frame will not be acquired from the draft, but created
  57. // anew. When a frame proxy is created in this manner it is assumed it has YET 
  58. // to be embedded.
  59. // 3. A frame proxy can be loaded in from storage. In most cases this works with
  60. // no trouble. Sometimes (in 1 case, actually ), however, an EMBEDDED frame proxy can 
  61. // be loaded with no containing frame available which designates it as an ORPHAN.
  62. //
  63. // Orphaned embedded frame proxies. An orphan frame proxy comes into being when a 
  64. // document is saved and then dragged into a container part without cloning the root 
  65. // frame. In this case the proxies will not have a containing frame and are considered
  66. // orphans. There is special case code in CEmbeddingShape to deal with this 
  67. // situation.
  68. //
  69. //
  70. // Also, in an attempt to be exception safe ( finally ) I have made the proxy
  71. // objects require a 2 phase init. First you construct the object, then you
  72. // MUST call one of the init methods for a particular derivative of CFrameProxy.
  73. // Due to the facet that methods that need to be called to init
  74. // frame proxies can fail, and since our exception handling mechanism does not
  75. // support constructors failing, a 2 phase init is required.
  76. //
  77. // There are other instances in this part where constructors can fail, a similar
  78. // solution is necessary in those instances as well.
  79. //
  80. //=============================================================================
  81.  
  82. class CFrameProxy
  83. {
  84. public:
  85.  
  86.     // -- Init --
  87.     CFrameProxy();
  88.     
  89.     void InitializeFrameProxy( Environment* ev, 
  90.                                 DrawEditor* editor, 
  91.                                 ODID frameID, 
  92.                                 ODFrame* frame );
  93.     
  94.     virtual ~CFrameProxy();
  95.     
  96.     // -- Accessors --
  97.     ODBoolean            IsFrameInMemory() const;
  98.     ODBoolean            IsFrameProxyInited() const;
  99.  
  100.     ODID                GetFrameID() const;
  101.     
  102.     // Get Frame tries to internalize the frame, if it isn't already
  103.     virtual ODFrame*    GetFrame(Environment* ev);
  104.     
  105.     // SetFrame can be an alternative way to construct a proxy in which case
  106.     // the frame needs to be acquired.
  107.     void                SetFrame(ODFrame* frame);
  108.  
  109.     // Storage
  110.     virtual ODBoolean    Read(Environment* ev, 
  111.                                 ODStorageUnit* storage, 
  112.                                 CCloneInfo* cloneInfo) = 0;
  113.     virtual void        Write(Environment* ev, 
  114.                                 ODStorageUnit* storage, 
  115.                                 CCloneInfo* cloneInfo) = 0;
  116.  
  117. protected:
  118.  
  119.     // Back pointer to the part for necessary interaction
  120.     DrawEditor*            fDrawEditor;
  121.     ODID                 fFrameID;
  122.     ODFrame*             fFrame;    
  123.  
  124. private:
  125.  
  126.     // The frame we are acting as proxy for.
  127.     ODBoolean            fWeAcquiredFrame;
  128.     ODBoolean             fIsInited;    
  129.  
  130. };
  131.  
  132.  
  133. //=============================================================================
  134. // CDisplayFrameProxy
  135. //
  136. //=============================================================================
  137. class CDisplayFrameProxy : public CFrameProxy
  138. {
  139. public:
  140.     // -- Init --
  141.     CDisplayFrameProxy();
  142.     void InitializeDisplayFrameProxy( Environment* ev, 
  143.                                         DrawEditor* editor, 
  144.                                         ODID frameID = kODNULLID, 
  145.                                         ODFrame* frame = kODNULL );
  146.     
  147.     virtual ~CDisplayFrameProxy();
  148.     
  149.     // Storage
  150.     virtual ODBoolean    Read(Environment* ev, 
  151.                                 ODStorageUnit* storage, 
  152.                                 CCloneInfo* cloneInfo);
  153.     virtual void        Write(Environment* ev, 
  154.                                 ODStorageUnit* storage, 
  155.                                 CCloneInfo* cloneInfo);
  156.  
  157. };
  158.  
  159.  
  160. //=============================================================================
  161. // CEmbeddedFrameProxy
  162. //
  163. //=============================================================================
  164. class CEmbeddedFrameProxy : public CFrameProxy
  165. {
  166. public:
  167.     // -- Init --
  168.     CEmbeddedFrameProxy();
  169.                             
  170.     void InitializeEmbeddedFrameProxy( Environment* ev, 
  171.                             DrawEditor* editor, 
  172.                             CEmbeddingShape* shape);
  173.                             
  174.     void InitializeEmbeddedFrameProxy( Environment* ev, 
  175.                         DrawEditor* editor, 
  176.                         CEmbeddingShape* shape, 
  177.                         ODFrame* containingFrame, 
  178.                         ODPart* part,
  179.                         ODTypeToken viewType = kODNullTypeToken,
  180.                         ODTypeToken presentation = kODNullTypeToken);
  181.                         
  182.     void InitializeEmbeddedFrameProxy( Environment* ev, 
  183.                         DrawEditor* editor, 
  184.                         CEmbeddingShape* shape, 
  185.                         ODID frameID, 
  186.                         ODFrame* containingFrame );
  187.     
  188.     virtual ~CEmbeddedFrameProxy();
  189.     
  190.     // -- Accessors --
  191.     
  192.     virtual ODFrame*    GetFrame(Environment* ev);
  193.     ODBoolean            IsOrphaned() const;
  194.     
  195.     ODID                GetContainingFrameID(Environment* ev) const;
  196.     void                SetContainingFrame(Environment* ev, ODID id);
  197.     ODFrame*            AcquireContainingFrame(Environment* ev);
  198.     
  199.     // -- Embedded Frames --
  200.     void                OffsetFrame(Environment* ev, ODPoint offset);        
  201.     void                ResizeFrame(Environment* ev, ODRect resizeRect);
  202.     void                RePositionFrameFacets(Environment* ev, ODPoint& topLeft);
  203.             
  204.     // Remove / Add frames to the visual hierarchy
  205.     ODBoolean            IsAttached(Environment* ev) const;
  206.     void                Attach(Environment* ev);    
  207.     void                Detach(Environment* ev);
  208.         
  209.     // Remove add frames from the document
  210.     ODBoolean            IsInLimbo(Environment* ev) const;
  211.     void                SetInLimbo(Environment* ev, ODBoolean isInLimbo);    
  212.         
  213.     void                Purge(Environment* ev);    
  214.     void                CloseAndPurge(Environment* ev);
  215.     void                RemoveAndPurge(Environment* ev);
  216.     
  217.     void                RenumberFrameSequences(Environment* ev, ODULong sequence, ODBoolean addOrRemove);
  218.     ODULong                FindNextSequence(Environment* ev, ODULong group);
  219.     
  220.     // Storage
  221.     ODBoolean    Read(Environment* ev, 
  222.                                 ODStorageUnit* storage, 
  223.                                 CCloneInfo* cloneInfo);
  224.     void        Write(Environment* ev, 
  225.                                 ODStorageUnit* storage, 
  226.                                 CCloneInfo* cloneInfo);
  227.     
  228.     // -- Facets --
  229.     void                CreateFacets(Environment* ev);
  230.     void                 RemoveFacets(Environment* ev);
  231.     
  232.     void                 CreateFacetsForContainer(Environment* ev, ODFacet* facet);
  233.     void                RemoveFacetsForContainer(Environment* ev, ODFacet* facet);
  234.  
  235. private:    
  236.     
  237.     // Back pointer to the embedding shape for necessary interaction
  238.     CEmbeddingShape*    fEmbeddingShape;
  239.             
  240.     // ID of container frame
  241.     ODID                fContainingFrameID;
  242.     
  243.     // Frame sequenceing ( remove / undo / redo )
  244.     ODULong                fSavedFrameSequence;
  245.     
  246.     // We store a reference to the ID of the part which owns the
  247.     // frame for we which we are acting as proxy. This is necessary
  248.     // to support lazy internalization and is used only in the case
  249.     // where an embedded shape is created ( or a frame is created 
  250.     // causing a new proxy to be added ). In this case we don't create
  251.     // a frame and, consequently, do not have a frame ID either. In 
  252.     // this case when the frame is called for we must create the embedded
  253.     // frame ourselves via the CreateEmbeddedFrame call which takes the part
  254.     // as a parameter.
  255.     // ODID                fPartID;
  256.     
  257.     // OpenDoc Bug: Can't store the PartID, must store the actual part reference.
  258.     // It appears that you can't create the part, then release it, then re-acquire
  259.     // it later
  260.     ODPart*             fPart;
  261.     
  262.     // Also, in the case where we are constructed with a part reference, we must also
  263.     // store a presentation and view type since we will be creating the frame 
  264.     // in proxy code.
  265.     ODTypeToken            fPresentation;
  266.     ODTypeToken            fViewType;
  267.     
  268.     // Used primarily do determine how to release the 
  269.     // ODFrame we are proxying
  270.     ODBoolean            fAttached;
  271. };
  272.  
  273.  
  274.  
  275. #endif